package com.cskaoyan.controller;

import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseParam;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.common.Constant;
import com.cskaoyan.bean.vo.*;
import com.cskaoyan.bean.vo.zy.ZYAdminUserListVO;
import com.cskaoyan.service.UserService_yjc;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("admin")
public class YJCUserController {
    @Autowired
    UserService_yjc userService_yjc;

    @RequestMapping("user/update")
    /**
     * http://182.92.235.201:8083/admin/user/update POST
     */
    public BaseRespVo userUpdate(@RequestBody ZYAdminUserListVO param){
        int data;
        try {
            data = userService_yjc.userUpdate(param);
        }catch (Exception e){
            e.printStackTrace();
            return BaseRespVo.exception(Constant.DB_EXCEPTION);
        }
        return BaseRespVo.success(data);
    }

    @RequestMapping("user/detail")
    public BaseRespVo userDetail(Integer id){
        ZYAdminUserListVO resultVO;
        try {
            resultVO = userService_yjc.uderDetail(id);
        }catch (Exception e){
            e.printStackTrace();
            return BaseRespVo.exception(Constant.DB_EXCEPTION);
        }
        return BaseRespVo.success(resultVO);
    }

    //将Handler方法和权限建立耦合关系，访问这个Hnadler方法需要注解中的权限

    @RequestMapping("user/list")
    public BaseRespVo<YJCUserVo> userList(BaseParam param,String username,String mobile,Integer userId) {
        CommonData<ZYAdminUserListVO> result = new CommonData<>();
        try {
            result = userService_yjc.userList(param,username,mobile,userId);
        }catch (Exception e){
            e.printStackTrace();
            return BaseRespVo.exception(Constant.DB_EXCEPTION);
        }
        return BaseRespVo.success(result);
        /*PageInfo pageInfo = userService_yjc.queryAllUsers();
        long total = pageInfo.getTotal();
        List list = pageInfo.getList();
        YJCUserVo yjcUserVo = new YJCUserVo((int) total, 1, 20, 1, list);
        return BaseRespVo.okyjc(yjcUserVo);*/
    }

//http://localhost:8083/admin/address/list?page=1&limit=20&name=1&userId=1&sort=add_time&order=desc
//{"data":{"total":1,"pages":1,"limit":20,"page":1,"list":[{"id":1,"name":"","userId":1,"province":"湖北","city":"武汉","county":"黄陂","addressDetail":"晃晃","areaCode":"21","tel":"13455667898","isDefault":false,"addTime":null,"updateTime":"2023-01-02 22:57:24.0","deleted":false}]},"errmsg":"成功","errno":0}
    @RequestMapping("address/list")
    public BaseRespVo<YJCAddressListVO> adressList(BasePageInfo pageInfo, String name, Integer userId) {
        CommonData data = userService_yjc.queryAllAddress(pageInfo,name,userId);

        return BaseRespVo.okyjc(data);
    }

    //@RequestMapping("collect/list")
    public BaseRespVo<YJCCollectListVO> collectList() {
        PageInfo pageInfo = userService_yjc.queryCollect();
        long total = pageInfo.getTotal();
        List list = pageInfo.getList();
        YJCUserVo yjcUserVo = new YJCUserVo((int) total, 1, 20, 1, list);
        return BaseRespVo.okyjc(yjcUserVo);
    }
   // @RequestMapping("footprint/list")
    public BaseRespVo<YJCFootprintListVO> footprintList() {
        PageInfo pageInfo = userService_yjc.queryFootprint();
        long total = pageInfo.getTotal();
        List list = pageInfo.getList();
        YJCUserVo yjcUserVo = new YJCUserVo((int) total, 1, 20, 1, list);
        return BaseRespVo.okyjc(yjcUserVo);
    }
    /*
    * http://182.92.235.201:8083/admin/history/list?page=1&limit=20&userId=1&keyword=1&sort=add_time&order=desc
    * {"errno":0,"data":{"total":20,"pages":1,"limit":20,"page":1,"list":[{"id":307,"userId":29,"keyword":"法拉利","from":"wx","addTime":"2023-01-02 21:16:30","updateTime":"2023-01-02 21:16:30","deleted":false},{"id":306,"userId":31,"keyword":"的合同工","from":"wx","addTime":"2023-01-02 19:41:11","updateTime":"2023-01-02 19:41:11","deleted":false},{"id":301,"userId":24,"keyword":"母亲节礼物","from":"wx","addTime":"2023-01-02 16:07:14","updateTime":"2023-01-02 16:07:14","deleted":false},{"id":293,"userId":24,"keyword":"奥利给3","from":"wx","addTime":"2023-01-02 15:23:20","updateTime":"2023-01-02 15:23:20","deleted":false},{"id":289,"userId":24,"keyword":"母亲节礼物","from":"wx","addTime":"2023-01-02 14:56:04","updateTime":"2023-01-02 14:56:04","deleted":false},{"id":287,"userId":24,"keyword":"母亲节礼物","from":"wx","addTime":"2023-01-02 14:49:36","updateTime":"2023-01-02 14:49:36","deleted":false},{"id":286,"userId":24,"keyword":"马小艳","from":"wx","addTime":"2023-01-02 14:26:05","updateTime":"2023-01-02 14:26:05","deleted":false},{"id":285,"userId":24,"keyword":"子母被","from":"wx","addTime":"2023-01-02 14:25:57","updateTime":"2023-01-02 14:25:57","deleted":false},{"id":283,"userId":34,"keyword":"专题","from":"wx","addTime":"2023-01-02 14:13:20","updateTime":"2023-01-02 14:13:20","deleted":false},{"id":282,"userId":24,"keyword":"母亲节礼物","from":"wx","addTime":"2023-01-02 14:02:35","updateTime":"2023-01-02 14:02:35","deleted":false},{"id":281,"userId":24,"keyword":"母亲节礼物","from":"wx","addTime":"2023-01-02 14:00:37","updateTime":"2023-01-02 14:00:37","deleted":false},{"id":280,"userId":24,"keyword":"母亲节礼物","from":"wx","addTime":"2023-01-02 13:50:54","updateTime":"2023-01-02 13:50:54","deleted":false},{"id":279,"userId":24,"keyword":"母亲节礼物","from":"wx","addTime":"2023-01-02 13:42:09","updateTime":"2023-01-02 13:42:09","deleted":false},{"id":275,"userId":24,"keyword":"母亲节礼物","from":"wx","addTime":"2023-01-02 10:45:04","updateTime":"2023-01-02 10:45:04","deleted":false},{"id":273,"userId":24,"keyword":"子母被","from":"wx","addTime":"2023-01-02 09:49:12","updateTime":"2023-01-02 09:49:12","deleted":false},{"id":272,"userId":24,"keyword":"子母被","from":"wx","addTime":"2023-01-02 09:48:40","updateTime":"2023-01-02 09:48:40","deleted":false},{"id":227,"userId":27,"keyword":"内裤","from":"wx","addTime":"2023-01-01 00:00:08","updateTime":"2023-01-01 00:00:08","deleted":false},{"id":226,"userId":27,"keyword":"111","from":"wx","addTime":"2022-12-31 23:58:44","updateTime":"2022-12-31 23:58:44","deleted":false},{"id":182,"userId":26,"keyword":"优惠卷","from":"wx","addTime":"2022-12-31 14:27:29","updateTime":"2022-12-31 14:27:29","deleted":false},{"id":176,"userId":24,"keyword":"母亲节礼物","from":"wx","addTime":"2022-12-31 12:07:42","updateTime":"2022-12-31 12:07:42","deleted":false}]},"errmsg":"成功"}
    * */
    @RequestMapping("history/list")
    public BaseRespVo<YJCHistoryListVO> historyList(BasePageInfo pageInfo, String keyword, Integer userId) {
//        PageInfo pageInfo = userService_yjc.queryHistory();
////        long total = pageInfo.getTotal();
////        List list = pageInfo.getList();
////        YJCUserVo  yjcUserVo = new YJCUserVo((int) total, 1, 20, 1, list);
////        return BaseRespVo.okyjc(yjcUserVo);
        CommonData data = userService_yjc.queryHistory(pageInfo,keyword,userId);
        return BaseRespVo.okyjc(data);
    }
    @RequestMapping("feedback/list")
    public BaseRespVo<YJCFeedbackListVO> feedbackList() {
        PageInfo pageInfo = userService_yjc.queryFeedback();
        long total = pageInfo.getTotal();
        List list = pageInfo.getList();
        YJCUserVo  yjcUserVo = new YJCUserVo((int) total, 1, 20, 1, list);
        return BaseRespVo.okyjc(yjcUserVo);
    }
}
